using QTool.BEPUphysics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QTool.BEPUphysics.Entities.Prefabs;
using QTool.NetFrame;
using QTool.BEPUphysics.Entities;
using QTool.BEPUphysics.CollisionShapes.ConvexShapes;
using QTool.BEPUphysics.CollisionShapes;

namespace QTool.NetFrame
{
    [RequireComponent(typeof(MeshFilter))]
    public class FixMeshCollider : FixCollider
    {

        //   public QTool.NetFrame.FixVector3 size = Vector3.one;
        public void Reset()
        {
            meshFilter =GetComponent<MeshFilter>();
        }
        public MeshFilter meshFilter;
        protected override EntityShape CreateShape()
        {
            if (meshFilter == null) return null;
            var vs = new FixVector3[meshFilter.mesh.vertices.Length];
            for (int i = 0; i < vs.Length; i++)
            {
                vs[i] = meshFilter.mesh.vertices[i];
            }
            var meshShape = new MobileMeshShape(vs, meshFilter.mesh.triangles, new AffineTransform(transform.lossyScale,FixQuaternion.Identity,FixVector3.Zero), MobileMeshSolidity.DoubleSided);
            meshShape.Volume = 1;
            return meshShape;// new QTool.BEPUphysics.Entities.Prefabs.
        }
        protected override void OnDrawGizmosSelected()
        {
            base.OnDrawGizmosSelected();
            Gizmos.DrawWireMesh(meshFilter.mesh, 0);
        }
    }

}